import type { Key, PageDTO, PageRes, SortDTO } from '@/types/global'
import type { AddCategory, Category, QueryCategory, UpdateCategory } from '@/types/category'
import { request } from '@/utils/request'

export function queryCategoryList(params: PageDTO & SortDTO & QueryCategory) {
  return request.get<PageRes<Category>>('/api/category', { params })
}

export function addCategory(data: AddCategory) {
  return request.post('/api/category', data)
}

export function getCategoryById(id: number) {
  return request.get<Category>('/api/category/' + id)
}

export function updateCategory(data: UpdateCategory) {
  return request.put('/api/category', data)
}

export function deleteCategoryByIds(idList: Key[]) {
  return request.delete('/api/category', {
    params: {
      idList: idList
    }
  })
}

export function queryAllCategory() {
  return request.get<Category[]>('/api/category/queryAllCategory')
}
